package net.spunofbook;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class TelaPrincipal extends Activity {

	TextView cliente, venda;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tela_principal);
		instanciarVariaveis();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.tela_principal, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Context v = getBaseContext();
		switch (item.getItemId()) {
		
			case R.id.telaPrincipalMenu_venda:
				chamarTelaVenda(v);
				break;
		
			case R.id.telaPrincipalMenu_cliente:
				chamarTelaCliente(v);
				break;
		
			default:
				break;
		}
		
		return true;
	}
	
	private void instanciarVariaveis(){
		cliente = (TextView) findViewById(R.id.telaPrincipal_cliente);
		cliente.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				chamarTelaCliente(getBaseContext());
			}
		});
		
		venda 	= (TextView) findViewById(R.id.telaPrincipal_venda);
		venda.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				chamarTelaVenda(getBaseContext());
			}
		});
	}
	
	private void chamarTelaCliente(Context context){
		startActivity(new Intent(context, TelaCliente.class));
		finish();
	}

	private void chamarTelaVenda(Context context){
		startActivity(new Intent(context, TelaVenda.class));
		finish();
	}
}
